// const path = require('path')
// const htmlWebpackPlugin = require('html-webpack-plugin')

import path from 'path'
import htmlWebpackPlugin from 'html-webpack-plugin'

console.log('------------dirName-----------------')
const dirName = path.dirname(import.meta.url).replace('file:///', '')
console.log(dirName)
console.log('------------dirName-----------------')

const config = {
    "mode": "production",
    "entry": "./src/index.js",
    output: {
        // webpack 如何输出结果的相关选项 注意：__dirname CommonJS规范中才有
        path: path.join(dirName, "dist"), // string (default)
        // 所有输出文件的目标路径
        // 必须是绝对路径（使用 Node.js 的 path 模块）
        filename: "dsb.js", // string (default)
    },
    // 为 webpack 配置插件
    plugins: [new htmlWebpackPlugin({
        template: './public/template.html'
    })],
    module: {
        rules: [
            {
                test: /\.css$/i,
                use: ["style-loader", "css-loader"],
            }, {
                test: /\.less$/i,
                use: ["style-loader", "css-loader", "less-loader"],
            }, {
                test: /\.(jpeg|gif|png|jpg)$/i,
                type: 'asset'
            }, {
                test: /\.(eot|svg|ttf|woff|woff2)$/i,
                type: 'asset/resource',
                generator: {
                    filename: 'font/[name].[hash:6][ext]'
                }
            }
        ],
    },
}

// module.exports = config
export default config